<script lang="ts" setup>
import TkiQrcode from '@/components/tki-qrcode/tki-qrcode'
import { useUserStore } from '@/store/user'

defineOptions({
  options: {
    styleIsolation: 'shared',
  },
})
const userStore = useUserStore()
const showQrcode = ref<boolean>(false)
const qrcodeRef = ref(null)

// const showQrcode = defineModel({
// 	type: Boolean,
// 	default: false
// })
// 二维码生成的内容
const getQrcodeContent = computed(() => {
  return `
			用户昵称: ${userStore.userInfo.nickname}
			手机号: ${userStore.userInfo.mobile}
		`
})

function handleQrcode() {
  showQrcode.value = true
  // if (userStore.userInfo.qrcode) return
  // console.log(qrcodeRef.value)
  qrcodeRef.value?._makeCode()
}
// 二维码生成的地址
function handleResult(value: any) {
  userStore.setUserQrcode(value)
}
</script>

<template>
  <view class="user-qrcode">
    <!-- 用户二维码 -->
    <view class="qrcode-box" @click="handleQrcode">
      <image class="qrcode" webp src="/src/static/images/qrcode.jpg" />
    </view>
    <!-- 二维码弹窗 -->
    <wd-popup
      v-model="showQrcode"
      lock-scroll
      position="bottom"
      custom-class="qrcode-popup"
      modal-style="qrcode-modal"
    >
      <view class="title">
        我的二维码
      </view>

      <view class="qrcode-img">
        <!-- <wd-loading v-if="!userStore.userInfo.qrcode" /> -->
        <!-- <image v-if="userStore.userInfo.qrcode" class="image" :src="userStore.userInfo.qrcode" /> -->
        <tki-qrcode ref="qrcodeRef" :val="getQrcodeContent" :size="600" @result="handleResult" />
      </view>
    </wd-popup>
  </view>
</template>

<style lang="scss" scoped>
	.user-qrcode {
  .qrcode-box {
    border-radius: 50%;
    position: absolute;
    right: 0;
    bottom: 0;
    box-shadow: 0px 5px 16px 0px rgba(0, 0, 0, 0.08);
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 24px;
    height: 24px;
    .qrcode {
      width: 14px;
      height: 14px;
    }
  }
  :deep(.qrcode-popup) {
    border-radius: 12px 12px 0px 0px;
    box-shadow: 0px -8px 10px 0px rgba(241, 244, 249, 1);
    padding: 31px 0 50px 0 !important;

    .title {
      font-size: 18px;
      font-weight: 500;
      line-height: 22px;
      text-align: center;
      padding-bottom: 17px;
    }

    .qrcode-img {
      border-radius: 8px;
      box-shadow: 0px 8px 14px 4px rgba(241, 244, 249, 1);
      background-color: #fff;
      width: 322px;
      height: 322px;
      margin: 0 auto;
      display: flex;
      justify-content: center;
      align-items: center;

      .image {
        padding: 11px;
        width: 300px;
        height: 300px;
        border-radius: 8px;
      }
    }
  }
  :deep(.wd-overlay) {
    background: rgba(255, 255, 255, 0);
  }
}
</style>
